<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>爱随行后台</title>
  <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
  <div class="layui-header">
    <div class="layui-logo layui-hide-xs layui-bg-black">爱随行后台</div>
    <!-- 头部区域（可配合layui 已有的水平导航） -->
    <ul class="layui-nav layui-layout-right">
      <li class="layui-nav-item layui-hide layui-show-md-inline-block">
        <a href="javascript:;">
          <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">
          后台管理人员
        </a>
      </li>
      <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
        <a href="javascript:;">
          <i class="layui-icon layui-icon-more-vertical"></i>
        </a>
      </li>
    </ul>
  </div>

  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
      <ul class="layui-nav layui-nav-tree" lay-filter="test">
        <li class="layui-nav-item layui-nav-itemed">
          <a class="" href="javascript:;">审核</a>
          <dl class="layui-nav-child">
            <dd ><a href="./auditAct.html">审核活动</a></dd>
            <dd class="layui-this" ><a href="./auditPublisher.html">审核活动发布者申请</a></dd>
          </dl>
        </li>
      </ul>
    </div>
  </div>

  <div class="layui-body">
    <!-- 内容主体区域 -->
    <table id="demo" lay-filter="test"></table>
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="success">通过</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reject">驳回</a>
    </script>



  </div>

  <div class="layui-footer">
    <!-- 底部固定区域 -->
    底部固定区域
  </div>
</div>
<script src="./layui/layui.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
  //JS
  layui.use(['element', 'layer', 'util'], function(){
    var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,$ = layui.$;

    //头部事件
    util.event('lay-header-event', {
      //左侧菜单事件
      menuLeft: function(othis){
        layer.msg('展开左侧菜单的操作', {icon: 0});
      }
      ,menuRight: function(){
        layer.open({
          type: 1
          ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
          ,area: ['260px', '100%']
          ,offset: 'rt' //右上角
          ,anim: 5
          ,shadeClose: true
        });
      }
    });

  });

  layui.use('table', function(){
    var table = layui.table;
    table.on('tool(test)', function(obj){
      var data = obj.data;
      if(obj.event === 'success'){
        //请求操作
        Audit(data.username,"success")
      } else if(obj.event === 'reject'){
        Audit(data.username,"fail");
      }
    });
    //第一个实例
    table.render({
      elem: '#demo'
      ,skin: 'row' //行边框风格
      ,even: true //开启隔行背景
      // ,size: 'sm' //小尺寸的表格
      , height: 500

      ,url: '/Audit/getAllAuditPublisherApplyed' //数据接口
      ,page: true //开启分页
      ,parseData: function(res) { //res 即为原始返回的数据
        return {
          "code": 0, //解析接口状态
          "msg": "提示文本", //解析提示文本
          "count": res.length, //解析数据长度
          "data": res //解析数据列表
        };
      }
      ,cols: [[ //表头
        {field: 'username', title: '用户名', width:500}
        ,{field: 'reason', title: '申请原因', width:500, sort: true}
        ,{fixed: 'right',title:'审核操作', width:200 ,align:'center', toolbar: '#barDemo'}
      ]]
    });
  });

  function Audit(name,behavior){
    $.ajax({
      url: "/person/auditPublisher",
      type: 'Get',
      //要啥时候休息呀
      data: {
        name: name,
        result: behavior
      },
      success: function (resp) {
        console.log("success",resp)
        if (resp.indexOf("审核通过")!==-1) {
          layer.msg('通过操作');
        } else {
          layer.msg('操作失败');
        }
        //刷新
        window.location.reload();

      },
      fail: function (resp) {
        console.log("fail",resp)
      }
    })
  }
</script>
</body>
</html>